package com.fowo.api.tiktok.controller;

import com.fowo.api.common.model.R;
import com.fowo.api.entity.ShopInfo;
import com.fowo.api.model.shop.info.ShopInfoVo;
import com.fowo.api.shein.service.SheinAuthService;
import com.fowo.api.tiktok.service.TiktokAuthService;
import com.fowo.api.tiktok.service.TiktokOrderService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/tiktok")
public class TiktokAuthController {

    @Resource
    private TiktokAuthService tiktokAuthService;
    @Resource
    private TiktokOrderService tiktokOrderService;

    @ApiOperation(value = "店铺应用授权", httpMethod = "POST")
    @PostMapping(path = {"/authorizate"})
    public R<String> getUrl(@RequestBody ShopInfoVo model){
        return R.data(() -> tiktokAuthService.getAuthorizateUrl("NAME_"+model.getShopName()));
    }

    /**
     * 店铺应用授权回调
     * @param code
     * @param state
     * @return
     */
    @GetMapping("/callback")
    public R callback(String code, String state){
        return R.run(() -> tiktokAuthService.getToken(code, state));
    }

    @ApiOperation(value = "刷新授权", httpMethod = "POST")
    @PostMapping("/refreshToken")
    public R refreshToken(Long shopId){
        return R.run(()->tiktokAuthService.refreshToken(shopId));
    }

//    @GetMapping("/getShops")
//    public R getAuthorizedShops(){
//        return R.run(() -> tiktokAuthService.getAuthorizedShops());
//    }

    @GetMapping("/package")
    public R getPackage(String orderId,String packageId,Long shopId){
       return R.run(() -> tiktokOrderService.getPackageShippingDocument(orderId,packageId, shopId));
    }
}
